package org.example.service.serviceImpl;

import org.example.model.Enum.OrderStatus;
import org.example.model.PoJo.Order;
import org.example.service.OrderRepository;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


//存储订单
public class MemoryOrderRepository implements OrderRepository {
    private static final Map<String, Order> orders = new ConcurrentHashMap<>();

    @Override
    public void save(Order order) {
        orders.put(order.getOrderId(), order);
    }

    @Override
    public Order findById(String orderId) {
        return orders.get(orderId);
    }

    @Override
    public void updateStatus(String orderId, OrderStatus status) {
        Order order = orders.get(orderId);
        if(order != null) {
            order.setStatus(status);
        }
    }

    @Override
    public void remove(String orderId) {
        orders.remove(orderId);
    }
}
